﻿namespace Anley.DomainDrivenDesign.Contract.DomainAdapter;

/// <summary>
/// 分页数据传输对象
/// </summary>
/// <typeparam name="TDtoEntity"></typeparam>
public class PagedDto<TDtoEntity>
    where TDtoEntity : class
{
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="totalCount"></param>
    /// <param name="records"></param>
    /// <param name="pageNumber"></param>
    /// <param name="pageSize"></param>
    public PagedDto(
        int totalCount,
        IEnumerable<TDtoEntity> records,
        int? pageNumber = null,
        int? pageSize = null)
    {
        TotalCount = totalCount;
        PageNumber = pageNumber ?? AneConsts.DefaultPageNumber;
        PageSize = pageSize ?? AneConsts.DefaultPageSize;
        Records = records;
    }

    /// <summary>
    /// 总数量
    /// </summary>
    public int TotalCount { get; set; }

    /// <summary>
    /// 页码
    /// </summary>
    public int PageNumber { get; set; }

    /// <summary>
    /// 每页数量
    /// </summary>
    public int PageSize { get; set; }

    /// <summary>
    /// 页数
    /// </summary>
    public int PageCount => (TotalCount - 1) / PageSize + 1;

    /// <summary>
    /// 记录
    /// </summary>
    public IEnumerable<TDtoEntity> Records { get; set; }
}